package com.jeecg.p3.system.service.impl;

import com.jeecg.p3.system.dao.ProductDao;
import com.jeecg.p3.system.entity.Course;
import com.jeecg.p3.system.entity.Product;
import com.jeecg.p3.system.service.ProductService;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: jeewx-boot-parent
 * @description: 产品业务处理类
 * @author: binbin
 * @create: 2020-09-21 09:22
 */
@Service("productService")
public class ProductServiceImpl implements ProductService {

    @Resource
    private ProductDao productDao;


    @Override
    public void doAdd(Product product) {
        productDao.insert(product);
    }

    @Override
    public void doEdit(Product product) {
        productDao.update(product);
    }

    @Override
    public void doDelete(Long id) {
        productDao.delete(id);
    }

    @Override
    public Product queryById(Long id) {
        return productDao.get(id);
    }

    @Override
    public PageList<Product> queryPageList(PageQuery<Product> pageQuery) {
        PageList<Product> result = new PageList<>();
        Integer itemCount = productDao.count(pageQuery);
        PageQueryWrapper<Product> wrapper = new PageQueryWrapper<Product>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
        List<Product> list = productDao.queryPageList(wrapper);
        Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
        result.setPagenation(pagenation);
        result.setValues(list);
        return result;
    }

    @Override
    public List<Product> find() {
        return productDao.find();
    }


}
